package com.example.scrollview.slice;

import com.example.scrollview.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.ScrollView;

public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        ScrollView scrollView = (ScrollView) findComponentById(ResourceTable.Id_scrollview);
        Button option_scroll = (Button) findComponentById(ResourceTable.Id_option_scroll);
        Button option_scroll2 = (Button) findComponentById(ResourceTable.Id_option_scroll2);

        option_scroll.setClickedListener(component -> {
            scrollView.fluentScrollByY(300); // 根据像素数平滑滚动。
        });

        option_scroll2.setClickedListener(component -> {
            scrollView.fluentScrollYTo(500); // 平滑滚动到指定位置。
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
